<template>
	<view>
		<u-navbar bgColor="#fff" :fixed="true" leftIconColor="#000" leftIconSize="42rpx" autoBack placeholder>
		</u-navbar>
		<view class="main-container">
			<view style="padding: 30rpx 0 ;font-size: 40rpx;">
				您当前的身份：{{myId}}
			</view>
			<view>
				<img :src="avatarUrl" style="margin: 50rpx 0;width: 400rpx;height: 400rpx;" />
			</view>
			<view class="change-btnList">
				<view v-for="(item,index) in changeList" :key="item.code">
					<view class="change-btn" @click="changeType(item)" :class="{couldChange:authority(item.code)}">
						{{item.title}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userType: '',
				userWindow: '',
				avatarUrl: '',
				changeList: [{
					title: '切换为普通用户',
					code: '001'
				}, {
					title: '切换为陪诊、陪护师',
					code: '002'
				}, {
					title: '切换为医生',
					code: '003'
				}]
			}
		},
		computed: {
			myId() {
				if (this.userWindow == '001') {
					return '普通用户'
				} else if (this.userWindow == '002') {
					return '陪诊、陪护师'
				} else if (this.userWindow == '003') {
					return '医生'
				}
			}
		},
		created() {
			this.userType = uni.getStorageSync('userType')
			this.userWindow = uni.getStorageSync('userWindow')
			let currentCode = this.changeList.findIndex(i => {
				return i.code == this.userWindow
			})
			this.avatarUrl = `http://www.peiyiyiliao.com/QRCodeShare/imgs/id_${this.userWindow}.png`
			this.changeList.splice(currentCode, 1)
		},
		methods: {
			changeType(item) {
				if (this.userType == '10' || this.userType == '60') {
					// if (this.userType == '00' || this.userType == '10' || this.userType == '60') {
					uni.showModal({
						title: '提示',
						content: `您没有权限${item.title}`
					})
				} else if (this.userType == '20' || this.userType == '30' || this.userType == '40') {
					if (item.code == '003') {
						uni.showModal({
							title: '提示',
							content: `您没有权限${item.title}`
						})
					} else {
						this.doChange(item)
					}
				} else {
					this.doChange(item)
				}
			},
			authority(code) {
				if (this.userType == '50') {
					return true
				} else if (this.userType == '00' || this.userType == '10' || this.userType == '60') {
					return false
				} else if (this.userType == '20' || this.userType == '30' || this.userType == '40') {
					if (code == '003') {
						return false
					} else if (code == '001' || code == '002') {
						return true
					}
				}
			},
			doChange(item) {
				uni.setStorageSync('userWindow', item.code)
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				setTimeout(() => {
					uni.hideLoading();
					uni.reLaunch({
						url: '/pages/mine/mine',
					})
				}, 300);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main-container {
		display: flex;
		flex-direction: column;
		align-items: center;
	}


	.change-btnList .couldChange {
		background-color: #4874cb;
	}

	.change-btn {
		font-size: 36rpx;
		width: 400rpx;
		text-align: center;
		background-color: #808080;
		margin-top: 40rpx;
		padding: 15rpx 0;
		color: white;
		border-radius: 40rpx;
	}
</style>